import {
  INCREMENT,
  GET_WORKORDER_LIST,
  SWITCH_LIST_TYPE,
  RESET_SEARCH_PARAMS,
  SET_SEARCH_TITLEORNUM,
  SET_SEARCH_CUSTOMER,
  SET_SEARCH_DATACENTER,
  SET_SEARCH_LEVEL,
  SET_SEARCH_WORKORDER_STATUS,
  SET_SEARCH_WORKORDER_TYPE,
  SET_SEARCH_ACCEPTTIME,
  SET_SEARCH_ENDTIME,
  SEND_REQUEST,
  RESPONSE_SUCCESS,
  SET_PAGENUM,
  SET_PAGESIZE
} from './mutationTypes';

export default {
  [INCREMENT](state, num) {
    state.count = state.count + num;
  },
  [GET_WORKORDER_LIST](state, res) {
    state.workOrderList = res.workOrderList;
    state.totalCount = res.totalCount;
  },
  [SWITCH_LIST_TYPE](state, index) {
    state.searchParams.item = index;
    state.workOrderList = [];
  },
  [RESET_SEARCH_PARAMS](state) {
    let temp = state.searchParams.item;
    state.searchParams = {
      item: temp,
      titleOrNum: '',
      erpCustomerId: '',
      datacenterid: '',
      datacentername: '',
      level: '',
      workOrderStatus: '',
      workOrderType: '',
      acceptTime: '',
      endTime: '',
      pageNum: 1,
      pageSize: 10
    };
  },
  [SET_SEARCH_TITLEORNUM](state, titleOrNum) {
    state.searchParams.titleOrNum = titleOrNum;
  },
  [SET_SEARCH_CUSTOMER](state, customerId) {
    state.searchParams.erpCustomerId = customerId;
  },
  [SET_SEARCH_DATACENTER](state, dataCenter) {
    state.searchParams.datacenterid = dataCenter.datacenterid;
    state.searchParams.datacentername = dataCenter.datacentername;
  },
  [SET_SEARCH_LEVEL](state, level) {
    state.searchParams.level = level;
  },
  [SET_SEARCH_WORKORDER_STATUS](state, status) {
    state.searchParams.workOrderStatus = status;
  },
  [SET_SEARCH_WORKORDER_TYPE](state, type) {
    state.searchParams.workOrderType = type;
  },
  [SET_SEARCH_ACCEPTTIME](state, time) {
    state.searchParams.acceptTime = time;
  },
  [SET_SEARCH_ENDTIME](state, time) {
    state.searchParams.endTime = time;
  },
  [SEND_REQUEST](state) {
    state.loading = true;
  },
  [RESPONSE_SUCCESS](state) {
    state.loading = false;
  },
  [SET_PAGENUM](state, pageNum) {
    state.searchParams.pageNum = pageNum;
  },
  [SET_PAGESIZE](state, pageSize) {
    state.searchParams.pageSize = pageSize;
  }
};
